﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UILifeBar : MonoBehaviour
{
    public static UILifeBar BillInstance { get; private set; }
    public static UILifeBar LanceInstance { get; private set; }

    public PlayerContext.EnumPlayer playerIdentity;
    private int life = 3;
    private Transform[] lifeImages;
    private Transform gameoverImage;
    private void Awake()
    {
        if (playerIdentity == PlayerContext.EnumPlayer.BillRizer)
        {
            BillInstance = this;
        }
        else if (playerIdentity == PlayerContext.EnumPlayer.LanceBean)
        {
            LanceInstance = this;
        }
        lifeImages = new Transform[]
        {
            transform.Find("生命1"),
            transform.Find("生命2"),
            transform.Find("生命3"),
            transform.Find("生命4"),
        };
        gameoverImage = transform.Find("GAMEOVER");
    }
    private void FixedUpdate()
    {

        for (int i = 0; i < lifeImages.Length; i++)
        {
            if (life - 1 > i)
            {
                lifeImages[i].gameObject.SetActive(true);
            }
            else
            {
                lifeImages[i].gameObject.SetActive(false);
            }
        }
        if (life <= 0)
        {
            gameoverImage.gameObject.SetActive(true);
        }
        else
        {
            gameoverImage.gameObject.SetActive(false);
        }
    }
    public void SetLife(int life)
    {
        this.life = life;
    }
}
